package com.bizmerce.ebms.engine.security;

import javax.xml.soap.AttachmentPart;
import javax.xml.soap.SOAPHeader;

public abstract class SecurityService implements SecurityServiceInterface {

	/**
	 * 
	 */
	public static final String GPKI = "com.bizmerce.ebms.engine.GpkiSecurityService";

	/**
	 * 
	 */
	public static final String NPKI = "com.bizmerce.ebms.engine.NpkiSecurityService";

	/**
	 * 
	 * @return
	 */
	public static SecurityService newInstance() {
		return newInstance(GPKI);
	}

	/**
	 * 
	 * @param type
	 * @return
	 */
	public static SecurityService newInstance(String type) {
		SecurityService securityService = null;
		try {
			Class clazz = Thread.currentThread().getContextClassLoader()
					.loadClass(type);
			securityService = (SecurityService) clazz.newInstance();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return securityService == null ? new NotApplySecurityService()
				: securityService;
	}
	
	public abstract void init(SecurityConfig config);

	/**
	 * 
	 * @param soapHeader
	 * @param payload
	 */
	public abstract void signature(SOAPHeader soapHeader, AttachmentPart payload);

	/**
	 * 
	 * @param is
	 */
	public abstract void encryption(AttachmentPart payload);

	/**
	 * 
	 * @param payload
	 */
	public abstract void decryption(AttachmentPart payload);

	/**
	 * 
	 * @param soapHeader
	 */
	public abstract void verification(SOAPHeader soapHeader,
			AttachmentPart payload);

	/**
	 * 
	 * @param soapHeader
	 * @param payload
	 */
	public abstract void signatureAndEncryption(SOAPHeader soapHeader,
			AttachmentPart payload);

	/**
	 * 
	 * @param soapHeader
	 * @param payload
	 */
	public abstract void verificationAndDecryption(SOAPHeader soapHeader,
			AttachmentPart payload);

	/**
	 * 
	 * @param payloads
	 */
	public abstract void base64Encode(AttachmentPart payloads);

	/**
	 * 
	 * @param payloads
	 */
	public abstract void base64Decode(AttachmentPart payloads);
}
